<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Class: ActiveBackground::Server</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />

    <script language="JavaScript" type="text/javascript">
    // <![CDATA[

        function toggleSource( id )
        {
          var elem
          var link

          if( document.getElementById )
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }
          else if ( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
            return false;

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
        }
      // ]]>
    </script>

  </head>

  <body>
  <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Class</span><br />ActiveBackground::Server</td>
  <td align="right">
    <table cellspacing=0 cellpadding=2>
      <tr valign="top">
        <td>In:</td>
        <td>

<a href="../../files/vendor/plugins/active_background/tasks/__/lib/active_background/server_rb.html">vendor/plugins/active_background/tasks/../lib/active_background/server.rb</a>
        </td>
      </tr>
    <tr>
      <td>Parent:</td>
      <td>
Object
     </td>
   </tr>
         </table>
        </td>
        </tr>
      </table>
 <!-- banner header -->

  <div id="bodyContent">
      <div id="content">

  <div class="description"><p>
<a href="../ActiveBackground.html">ActiveBackground</a> server is
responsible for setting up a DRb server with a <a
href="Manager.html">ActiveBackground::Manager</a> instance (Singleton).
</p>
<h2>Creation</h2>
<p>
<a href="Server.html">ActiveBackground::Server</a> uses a <a
href="../ActiveBackground.html">ActiveBackground</a>:<a
href="Manager.html">Manager</a> instance to start a DRb server based on the
configuration file. It is also possible to pass the arguments by the <a
href="Server.html#M000092">ActiveBackground::Server.start</a> method. This
will overwrite the settings in the configuration file located in ether in
the rails config dir (if installed as rails plugin) or in the config
directory of <a href="../ActiveBackground.html">ActiveBackground</a>.
</p>
<p>
See <a href="Configuration.html">ActiveBackground::Configuration</a> for
more information
</p>
<p>
The following example starts the DRB server:
</p>
<pre>
  ActiveBackground::Server.start()
</pre>
<h2>Termination</h2>
<p>
<a href="Server.html">ActiveBackground::Server</a> is shutdown by killing
the proces that is started by the <a
href="Server.html#M000092">ActiveBackground::Server.start</a>() method. The
server is given chance to cleanup the threads (and store queued processes
in dumpfile). This file can be loaded again when starting up the server.
</p>
<pre>
  ActiveBackground::Server.stop()
</pre>
</div>



  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000101">defaults</a></li>
  <li><a href="#M000100">delete_windows_service</a></li>
  <li><a href="#M000103">info</a></li>
  <li><a href="#M000099">install_windows_service</a></li>
  <li><a href="#M000095">quick_start_windows</a></li>
  <li><a href="#M000105">read</a></li>
  <li><a href="#M000102">require_windows_libs</a></li>
  <li><a href="#M000096">restart_windows_service</a></li>
  <li><a href="#M000094">run_in_background</a></li>
  <li><a href="#M000092">start</a></li>
  <li><a href="#M000097">start_windows_service</a></li>
  <li><a href="#M000093">stop</a></li>
  <li><a href="#M000098">stop_windows_service</a></li>
  <li><a href="#M000104">write</a></li>
  </ul>


<div class="sectiontitle">Included Modules</div>
<ul>
  <li>Win32</li>
</ul>






<div class="sectiontitle">Public Class methods</div>
<div class="method">
  <div class="title">
    <a name="M000100"></a><b>delete_windows_service</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000100_source')" id="l_M000100_source">show source</a> ]</p>

  <div id="M000100_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 198</span>
198:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">delete_windows_service</span>
199:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_windows_libs</span>
200:       
201:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Service</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
202:         <span class="ruby-keyword kw">begin</span>
203:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stop_windows_service</span>
204:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Trying to delete the service&quot;</span>
205:           <span class="ruby-constant">Service</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
206:           <span class="ruby-keyword kw">while</span> <span class="ruby-constant">Service</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
207:             <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Trying to delete service.&quot;</span>
208:             <span class="ruby-identifier">sleep</span> <span class="ruby-value">2</span>
209:           <span class="ruby-keyword kw">end</span>
210:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">'Service has been removed'</span>
211:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
212:           <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>
213:         <span class="ruby-keyword kw">end</span>
214:       <span class="ruby-keyword kw">end</span>
215:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000099"></a><b>install_windows_service</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000099_source')" id="l_M000099_source">show source</a> ]</p>

  <div id="M000099_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 180</span>
180:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">install_windows_service</span>
181:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_windows_libs</span>
182:       
183:       <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">Service</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)     
184:         <span class="ruby-identifier">svc</span> = <span class="ruby-constant">Service</span>.<span class="ruby-identifier">new</span>
185:         <span class="ruby-identifier">svc</span>.<span class="ruby-identifier">create_service</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
186:           <span class="ruby-identifier">s</span>.<span class="ruby-identifier">service_name</span> = <span class="ruby-value str">&quot;ActiveBackground&quot;</span>
187:           <span class="ruby-identifier">s</span>.<span class="ruby-identifier">display_name</span> = <span class="ruby-value str">&quot;Active Background&quot;</span>
188:           <span class="ruby-identifier">s</span>.<span class="ruby-identifier">binary_path_name</span> = <span class="ruby-value str">&quot;ruby &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">__FILE__</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/../../script/windows_service.rb&quot;</span>)
189:           <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">binary_path_name</span>
190:         <span class="ruby-keyword kw">end</span>
191:         <span class="ruby-identifier">svc</span>.<span class="ruby-identifier">close</span>
192:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Registered Service&quot;</span>
193:       <span class="ruby-keyword kw">else</span>
194:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Service already registered&quot;</span>
195:       <span class="ruby-keyword kw">end</span>
196:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000095"></a><b>quick_start_windows</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000095_source')" id="l_M000095_source">show source</a> ]</p>

  <div id="M000095_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 120</span>
120:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">quick_start_windows</span>
121:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">delete_windows_service</span>
122:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">install_windows_service</span>
123:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">restart_windows_service</span>
124:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000102"></a><b>require_windows_libs</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000102_source')" id="l_M000102_source">show source</a> ]</p>

  <div id="M000102_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 221</span>
221:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_windows_libs</span>
222:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'rubygems'</span>
223:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'win32/service'</span>
224:       <span class="ruby-identifier">include</span> <span class="ruby-constant">Win32</span>
225:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000096"></a><b>restart_windows_service</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000096_source')" id="l_M000096_source">show source</a> ]</p>

  <div id="M000096_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 126</span>
126:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">restart_windows_service</span>
127:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stop_windows_service</span>
128:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start_windows_service</span>
129:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000094"></a><b>run_in_background</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000094_source')" id="l_M000094_source">show source</a> ]</p>

  <div id="M000094_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 116</span>
116:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">run_in_background</span>
117:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start_windows_service</span>
118:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000092"></a><b>start</b>(options={})
  </div>
  <div class="description">

  <p>
Start the <a href="Server.html">Server</a>
</p>
<p>
The server uses the ActiveBackground::Base.defaults to start the server.
However configuration options can be overwriten by using the
config/active_background.yml file. This starts the DRb service with a <a
href="Manager.html">ActiveBackground::Manager</a> instance (Singleton). And
closes with <tt>DRb.thread.join</tt> that runs till the proces is killed.
</p>
<ul>
<li><tt>:host</tt>: the host where the <a
href="Server.html">ActiveBackground::Server</a> must be setup on

</li>
<li><tt>:port</tt>: the port where the <a
href="Server.html">ActiveBackground::Server</a> must be setup on

</li>
<li><tt>:config_file</tt>: the configuration file that needs to be read
(options pased will not be overwritten)

</li>
<li><tt>:logging</tt>: you can enable or disable logging with true or false

</li>
<li><tt>:background</tt>: you can enable or disable running in background with
true or false

</li>
<li><tt>:rails</tt>: you can enable or disable loading rails with true or false

</li>
</ul>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000092_source')" id="l_M000092_source">show source</a> ]</p>

  <div id="M000092_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 56</span>
56:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">options</span>={})
57:       <span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge!</span>({<span class="ruby-identifier">:server</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:master</span>})
58:       <span class="ruby-keyword kw">begin</span>
59:         <span class="ruby-comment cmt"># load configuration from rails config file,</span>
60:         <span class="ruby-comment cmt"># or load file from local config file</span>
61:         <span class="ruby-comment cmt"># if both don't exist default to internal defaults</span>
62:         <span class="ruby-identifier">config</span> = <span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">instance</span>
63:         <span class="ruby-identifier">server_options</span> = {<span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">server</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:server</span>]).<span class="ruby-identifier">host</span>, <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">server</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:server</span>]).<span class="ruby-identifier">port</span>}
64:                 
65:         <span class="ruby-comment cmt"># the uri where we want to make our DRb available</span>
66:         <span class="ruby-identifier">uri</span> = <span class="ruby-node">&quot;druby://#{server_options[:host]}:#{server_options[:port]}&quot;</span>
67:         
68:         <span class="ruby-comment cmt"># Start up DRb with URI and instance of ActiveBackground::Manager</span>
69:         <span class="ruby-identifier">manager</span> = <span class="ruby-constant">ActiveBackground</span><span class="ruby-operator">::</span><span class="ruby-constant">Manager</span>.<span class="ruby-identifier">instance</span>
70:         <span class="ruby-identifier">manager</span>.<span class="ruby-identifier">init</span>
71:         <span class="ruby-identifier">manager</span>.<span class="ruby-identifier">config</span>=<span class="ruby-identifier">config</span>
72:         <span class="ruby-identifier">manager</span>.<span class="ruby-identifier">name</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:server</span>])
73:         <span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>( <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">manager</span> )
74:         
75:         <span class="ruby-comment cmt"># Show some statistics</span>
76:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">info</span>()
77:         <span class="ruby-comment cmt"># Write a file with the Process id so we can kill it</span>
78:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">write</span>()
79: 
80:         <span class="ruby-constant">DRb</span>.<span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
81:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
82:         <span class="ruby-identifier">logger</span> = <span class="ruby-identifier">config</span>.<span class="ruby-identifier">logger</span>
83:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">&quot;\n******************************************\n&quot;</span> <span class="ruby-operator">+</span>
84:                       <span class="ruby-node">&quot;Exception: #{e.to_s} - (#{e.class})\n&quot;</span> <span class="ruby-operator">+</span>
85:                       <span class="ruby-value str">&quot;Server: running server failed\n&quot;</span> <span class="ruby-operator">+</span>
86:                       <span class="ruby-value str">&quot;----------------BACKTRACE-----------------\n&quot;</span> <span class="ruby-operator">+</span>
87:                                 <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span>
88:                       <span class="ruby-value str">&quot;-------------------END--------------------\n&quot;</span> <span class="ruby-operator">+</span>
89:                       <span class="ruby-value str">&quot;\n******************************************\n&quot;</span> )
90:       <span class="ruby-keyword kw">end</span>
91:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000097"></a><b>start_windows_service</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000097_source')" id="l_M000097_source">show source</a> ]</p>

  <div id="M000097_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 131</span>
131:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start_windows_service</span>
132:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_windows_libs</span>
133:       
134:       <span class="ruby-comment cmt"># we can only start a service if it exists (installed)</span>
135:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Service</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)     
136:         <span class="ruby-identifier">s</span> = <span class="ruby-constant">Service</span>.<span class="ruby-identifier">status</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
137:         <span class="ruby-comment cmt"># check if the service is not already running</span>
138:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'running'</span>
139:           <span class="ruby-constant">Service</span>.<span class="ruby-identifier">start</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
140:           <span class="ruby-comment cmt"># wait till the service has started before giving back control</span>
141:           <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'running'</span>
142:             <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot; * Service starting wait please. Current status: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span>
143:             <span class="ruby-identifier">sleep</span> <span class="ruby-value">2</span>
144:             <span class="ruby-identifier">s</span> = <span class="ruby-constant">Service</span>.<span class="ruby-identifier">status</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
145:           <span class="ruby-keyword kw">end</span>
146:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Service is started.&quot;</span>
147:         <span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># inform if the service was already started</span>
148:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;service has already been started&quot;</span>
149:         <span class="ruby-keyword kw">end</span>
150:       <span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># service does not exist</span>
151:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Service does not exist please run rake active_background:install_windows_service&quot;</span>
152:       <span class="ruby-keyword kw">end</span>
153:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000093"></a><b>stop</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000093_source')" id="l_M000093_source">show source</a> ]</p>

  <div id="M000093_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 93</span>
 93:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stop</span>
 94:       <span class="ruby-identifier">config</span> = <span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">instance</span>
 95:       
 96:       <span class="ruby-comment cmt"># load configuration from rails config file,</span>
 97:       <span class="ruby-comment cmt"># or load file from local config file</span>
 98:       <span class="ruby-comment cmt"># if both don't exist default to internal defaults</span>
 99:       <span class="ruby-keyword kw">begin</span>
100:         <span class="ruby-keyword kw">begin</span> <span class="ruby-comment cmt"># try to load rails</span>
101:           <span class="ruby-identifier">require</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">__FILE__</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/../../../../config/boot.rb&quot;</span>
102:           <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@@defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">load</span>(<span class="ruby-node">&quot;#{RAILS_ROOT}/config/#{@@defaults[:config_file]}&quot;</span>))
103:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span> <span class="ruby-comment cmt"># loading of rails failed</span>
104:           <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@@defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">__FILE__</span>) <span class="ruby-operator">+</span> <span class="ruby-node">&quot;/../config/#{@@defaults[:config_file]}&quot;</span>))
105:         <span class="ruby-keyword kw">end</span>
106:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span> <span class="ruby-comment cmt"># loading of local file failed</span>
107:         <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@@defaults</span>
108:       <span class="ruby-keyword kw">end</span>
109:       
110:       <span class="ruby-comment cmt"># the uri where we want to make our DRb available</span>
111:       <span class="ruby-identifier">uri</span> = <span class="ruby-node">&quot;druby://#{options[:host]}:#{options[:port]}&quot;</span>
112:       
113:       <span class="ruby-comment cmt"># TODO: need a way to kill the DRb server and letting all the task shutdown nicely</span>
114:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000098"></a><b>stop_windows_service</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000098_source')" id="l_M000098_source">show source</a> ]</p>

  <div id="M000098_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 155</span>
155:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stop_windows_service</span>
156:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_windows_libs</span>
157:       
158:       <span class="ruby-comment cmt"># we can only start a service if it exists (installed)</span>
159:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Service</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
160:         <span class="ruby-identifier">s</span> = <span class="ruby-constant">Service</span>.<span class="ruby-identifier">status</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
161:         <span class="ruby-comment cmt"># check if the service is not already stopped</span>
162:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'stopped'</span>
163:           <span class="ruby-comment cmt"># self.stop # allow the server to terminate and save its jobs          </span>
164:           <span class="ruby-constant">Service</span>.<span class="ruby-identifier">stop</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
165:           <span class="ruby-comment cmt"># wait till the service has stopped before giving back control</span>
166:           <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'stopped'</span>
167:             <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot; * Service stoping wait please. Current status: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">current_state</span>
168:             <span class="ruby-identifier">sleep</span> <span class="ruby-value">2</span>
169:             <span class="ruby-identifier">s</span> = <span class="ruby-constant">Service</span>.<span class="ruby-identifier">status</span>(<span class="ruby-value str">&quot;ActiveBackground&quot;</span>)
170:           <span class="ruby-keyword kw">end</span>
171:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">' * Need to wait 30 seconds to shutdown ....'</span>
172:           <span class="ruby-identifier">sleep</span> <span class="ruby-value">30</span>
173:         <span class="ruby-keyword kw">end</span>
174:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Service is stopped.&quot;</span>
175:       <span class="ruby-keyword kw">else</span>
176:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Service does not exist please run rake active_background:install_windows_service&quot;</span>
177:       <span class="ruby-keyword kw">end</span>
178:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>

<div class="sectiontitle">Private Class methods</div>
<div class="method">
  <div class="title">
    <a name="M000103"></a><b>info</b>()
  </div>
  <div class="description">

  <p>
output some statistics
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000103_source')" id="l_M000103_source">show source</a> ]</p>

  <div id="M000103_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 229</span>
229:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">info</span>
230:         <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;DRb URI: #{DRb.uri}&quot;</span>
231:         <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;DRb Pid: #{Process.pid}&quot;</span>
232:       <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000105"></a><b>read</b>()
  </div>
  <div class="description">

  <p>
reading the pid so we can kill the proces later on
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000105_source')" id="l_M000105_source">show source</a> ]</p>

  <div id="M000105_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 240</span>
240:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>
241:         <span class="ruby-identifier">line</span> = <span class="ruby-keyword kw">nil</span>
242:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">__FILE__</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/../../tmp/ActiveBackground.pid&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
243:           <span class="ruby-identifier">line</span> = <span class="ruby-identifier">file</span>.<span class="ruby-identifier">gets</span>
244:         <span class="ruby-keyword kw">end</span>
245:         
246:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">to_i</span>
247:       <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000104"></a><b>write</b>()
  </div>
  <div class="description">

  <p>
saving the pid so we can kill the proces later on
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000104_source')" id="l_M000104_source">show source</a> ]</p>

  <div id="M000104_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 235</span>
235:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">write</span>
236:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>( <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">__FILE__</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/../../tmp/ActiveBackground.pid&quot;</span>, <span class="ruby-value str">'w+'</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>) }
237:       <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>

<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000101"></a><b>defaults</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000101_source')" id="l_M000101_source">show source</a> ]</p>

  <div id="M000101_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/server.rb, line 217</span>
217:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">defaults</span>
218:       <span class="ruby-ivar">@@defaults</span>
219:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
</div>

  </div>

    </body>
</html>